package kr.co.goodwilldd.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.co.goodwilldd.service.menus.IMenuService;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;

public class MenuInterceptor extends HandlerInterceptorAdapter {
	IMenuService iMenuService;

	public void setiMenuService(IMenuService iMenuService) {
		this.iMenuService = iMenuService;
	}

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		if (!isResourceHandler(handler))
			request.setAttribute("menus", iMenuService.getTree());
	}

	private boolean isResourceHandler(Object handler) {
		return handler instanceof ResourceHttpRequestHandler;
	}
}
